import 'package:get/get.dart';
import 'package:logger/logger.dart';
import 'package:vischat/core/controller/auth_service.dart';
import 'package:vischat/core/controller/global_service.dart';
import 'package:vischat/core/service/network/api_service.dart';
import 'package:vischat/core/service/storage/storage_manager.dart';
import 'package:vischat/data/datasources/local/common_local.dart';
import 'package:vischat/data/datasources/local/secure_local.dart';

class AppBinding implements Bindings {
  @override
  void dependencies() async {
    // permanent: true, // 页面路由切换时不销毁
    // fenix: true, // 销毁后再次使用时自动重建

    // 注册日志
    Get.lazyPut(() => Logger(), fenix: true);

    // 注册异步存储
    final storage = await StorageManager.create();
    Get.lazyPut(() => storage, fenix: true);
    // 注册本地存储工具
    Get.lazyPut(() => SecureLocal(Get.find()), fenix: true);
    Get.lazyPut(() => CommonLocal(Get.find()), fenix: true);

    // 注册网络服务
    Get.put<ApiService>(ApiService(Get.find(), Get.find()), permanent: true);

    // 注册全局服务
    Get.put<AuthService>(AuthService(), permanent: true);
    Get.put<GlobalService>(GlobalService(), permanent: true);
  }
}
